package com.ruoyi.Course.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.Course.mapper.StudyCourseMapper;
import com.ruoyi.Course.domain.StudyCourse;
import com.ruoyi.Course.service.IStudyCourseService;

/**
 * CourseService业务层处理
 * 
 * @author luobom
 * @date 2021-12-03
 */
@Service
public class StudyCourseServiceImpl implements IStudyCourseService 
{
    @Autowired
    private StudyCourseMapper studyCourseMapper;

    @Override
    public int updatedefaultcourse() {
        return studyCourseMapper.updatedefaultcourse(String.valueOf(SecurityUtils.getUserId()));
    }

    @Override
    public int updatedefaultcourseset(Map m) {
        return studyCourseMapper.setupdatedefaultcourse(m);
    }

    @Override
    public StudyCourse GetDefaultCourse() {
        StudyCourse s = studyCourseMapper.GetDefaultCourse(String.valueOf(SecurityUtils.getUserId()));
        if(s==null) {
            s=new StudyCourse();
        }
        return s;
    }

    /**
     * 查询Course
     * 
     * @param uid Course主键
     * @return Course
     */
    @Override
    public StudyCourse selectStudyCourseByUid(String uid)
    {
        //过滤其它用户的值 改xml文件实在太麻烦了
        StudyCourse stu=studyCourseMapper.selectStudyCourseByUid(uid);
        if(stu!=null) {
            if(!stu.getCreateBy().equals(String.valueOf(SecurityUtils.getUserId()))){
                stu=null;
            }
        }
        return stu;
    }

    /**
     * 查询Course列表
     * 
     * @param studyCourse Course
     * @return Course
     */
    @Override
    public List<StudyCourse> selectStudyCourseList(StudyCourse studyCourse)
    {
        studyCourse.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return studyCourseMapper.selectStudyCourseList(studyCourse);
    }

    /**
     * 新增Course
     * 
     * @param studyCourse Course
     * @return 结果
     */
    @Override
    public int insertStudyCourse(StudyCourse studyCourse)
    {
        studyCourse.setCreateTime(DateUtils.getNowDate());
        studyCourse.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return studyCourseMapper.insertStudyCourse(studyCourse);
    }

    /**
     * 修改Course
     * 
     * @param studyCourse Course
     * @return 结果
     */
    @Override
    public int updateStudyCourse(StudyCourse studyCourse)
    {
        studyCourse.setUpdateTime(DateUtils.getNowDate());
        return studyCourseMapper.updateStudyCourse(studyCourse);
    }

    /**
     * 批量删除Course
     * 
     * @param uids 需要删除的Course主键
     * @return 结果
     */
    @Override
    public int deleteStudyCourseByUids(String[] uids)
    {
        return studyCourseMapper.deleteStudyCourseByUids(uids);
    }

    /**
     * 删除Course信息
     * 
     * @param uid Course主键
     * @return 结果
     */
    @Override
    public int deleteStudyCourseByUid(String uid)
    {
        return studyCourseMapper.deleteStudyCourseByUid(uid);
    }
}
